/*!
	wow.export (https://github.com/Kruithne/wow.export)
	Authors: Kruithne <kruithne@gmail.com>, Marlamin <marlamin@marlamin.com>
	License: MIT
 */

// Retrieved from https://wowdev.wiki/M2#Key_Bone_Names
const BONE_NAMES = {
	0: 'ArmL',
	1: 'ArmR',
	2: 'ShoulderL',
	3: 'ShoulderR',
	4: 'SpineLow',
	5: 'Waist',
	6: 'Head',
	7: 'Jaw',
	8: 'IndexFingerR',
	9: 'MiddleFingerR',
	10: 'PinkyFingerR',
	11: 'RingFingerR',
	12: 'ThumbR',
	13: 'IndexFingerL',
	14: 'MiddleFingerL',
	15: 'PinkyFingerL',
	16: 'RingFingerL',
	17: 'ThumbL',
	18: '$BTH',
	19: '$CSR',
	20: '$CSL',
	21: '_Breath',
	22: '_Name',
	23: '_NameMount',
	24: '$CHD',
	25: '$CCH',
	26: 'Root',
	27: 'Wheel1',
	28: 'Wheel2',
	29: 'Wheel3',
	30: 'Wheel4',
	31: 'Wheel5',
	32: 'Wheel6',
	33: 'Wheel7',
	34: 'Wheel8',
	35: 'FaceAttenuation',
	36: 'EXP_C1_Cape1',
	37: 'EXP_C1_Cape2',
	38: 'EXP_C1_Cape3',
	39: 'EXP_C1_Cape4',
	40: 'EXP_C1_Cape5',
	41: 'EXP_C1_Tail1',
	42: 'EXP_C1_Tail2',
	43: 'EXP_C1_LoinBk1',
	44: 'EXP_C1_LoinBk2',
	45: 'EXP_C1_LoinBk3',
	48: 'EXP_C1_Spine2',
	49: 'EXP_C1_Neck1',
	50: 'EXP_C1_Neck2',
	51: 'EXP_C1_Pelvis1',
	52: 'Buckle',
	53: 'Chest',
	54: 'Main',
	55: 'EXP_R1_Leg1Twist1',
	56: 'EXP_L1_Leg1Twist1',
	57: 'EXP_R1_Leg2Twist1',
	58: 'EXP_L1_Leg2Twist1',
	59: 'FootL',
	60: 'FootR',
	61: 'ElbowR',
	62: 'ElbowL',
	63: 'EXP_L1_Shield1',
	64: 'HandR',
	65: 'HandL',
	66: 'WeaponR',
	67: 'WeaponL',
	68: 'SpellHandL',
	69: 'SpellHandR',
	70: 'EXP_R1_Leg1Twist3',
	71: 'EXP_L1_Leg1Twist3',
	72: 'EXP_R1_Arm1Twist2',
	73: 'EXP_L1_Arm1Twist2',
	74: 'EXP_R1_Arm1Twist3',
	75: 'EXP_L1_Arm1Twist3',
	76: 'EXP_R1_Arm2Twist2',
	77: 'EXP_L1_Arm2Twist2',
	78: 'EXP_R1_Arm2Twist3',
	79: 'EXP_L1_Arm2Twist3',
	80: 'ForearmR',
	81: 'ForearmL',
	82: 'EXP_R1_Arm1Twist1',
	83: 'EXP_L1_Arm1Twist1',
	84: 'EXP_R1_Arm2Twist1',
	85: 'EXP_L1_Arm2Twist1',
	86: 'EXP_R1_FingerClawA1',
	87: 'EXP_R1_FingerClawB1',
	88: 'EXP_L1_FingerClawA1',
	89: 'EXP_L1_FingerClawB1',
	190: '_BackCloak',
	191: 'face_hair_00_M_JNT',
	192: 'face_beard_00_M_JNT',
	193: 'face_cheek_02_L_SkinPoint',
	194: 'face_cheek_02_R_SkinPoint',
	195: 'face_eyeCornerIn_00_L_SkinPoint',
	196: 'face_eyeCornerIn_00_R_SkinPoint',
	197: 'face_eyeCornerOut_00_L_SkinPoint',
	198: 'face_eyeCornerOut_00_R_SkinPoint',
	199: 'face_eyebrow_00_L_SkinPoint',
	200: 'face_eyebrow_00_M_SkinPoint',
	201: 'face_eyebrow_00_R_SkinPoint',
	202: 'face_eyebrow_01_L_SkinPoint',
	203: 'face_eyebrow_01_R_SkinPoint',
	204: 'face_eyebrow_02_L_SkinPoint',
	205: 'face_eyebrow_02_R_SkinPoint',
	206: 'face_eyebrow_03_L_SkinPoint',
	207: 'face_eyebrow_03_R_SkinPoint',
	208: 'face_eyelidBot_00_L_SkinPoint',
	209: 'face_eyelidBot_00_R_SkinPoint',
	210: 'face_eyelidBot_01_L_SkinPoint',
	211: 'face_eyelidBot_01_R_SkinPoint',
	212: 'face_eyelidBot_02_L_SkinPoint',
	213: 'face_eyelidBot_02_R_SkinPoint',
	214: 'face_eyelidTop_00_L_SkinPoint',
	215: 'face_eyelidTop_00_R_SkinPoint',
	216: 'face_eyelidTop_01_L_SkinPoint',
	217: 'face_eyelidTop_01_R_SkinPoint',
	218: 'face_eyelidTop_02_L_SkinPoint',
	219: 'face_eyelidTop_02_R_SkinPoint',
	220: 'face_noseBridge_00_L_SkinPoint',
	221: 'face_noseBridge_00_R_SkinPoint',
	222: 'face_overEye_00_L_SkinPoint',
	223: 'face_overEye_00_R_SkinPoint',
	224: 'face_overOuterEye_00_L_SkinPoint',
	225: 'face_overOuterEye_00_R_SkinPoint',
	226: 'face_underEye_00_L_SkinPoint',
	227: 'face_underEye_00_R_SkinPoint',
	228: 'face_cheekPuff_00_L_SkinPoint',
	229: 'face_cheekPuff_00_R_SkinPoint',
	230: 'face_cheek_00_L_SkinPoint',
	231: 'face_cheek_00_R_SkinPoint',
	232: 'face_cheek_01_L_SkinPoint',
	233: 'face_cheek_01_R_SkinPoint',
	234: 'face_chin_00_L_SkinPoint',
	235: 'face_chin_00_M_SkinPoint',
	236: 'face_chin_00_R_SkinPoint',
	237: 'face_ear_00_L_SkinPoint',
	238: 'face_ear_00_R_SkinPoint',
	239: 'face_jaw_01_M_SkinPoint',
	240: 'face_jowl_00_L_SkinPoint',
	241: 'face_jowl_00_R_SkinPoint',
	242: 'face_jowl_01_L_SkinPoint',
	243: 'face_jowl_01_R_SkinPoint',
	244: 'face_lipBotBase_00_M_SkinPoint',
	245: 'face_lipTopBase_00_M_SkinPoint',
	246: 'face_mouthCorner_00_L_SkinPoint',
	247: 'face_mouthCorner_00_R_SkinPoint',
	248: 'face_mouthCurlBot_00_M_SkinPoint',
	249: 'face_mouthCurlTop_00_M_SkinPoint',
	250: 'face_mouth_00_M_SkinPoint',
	251: 'face_nasLab_00_L_SkinPoint',
	252: 'face_nasLab_00_R_SkinPoint',
	253: 'face_nasLab_01_L_SkinPoint',
	254: 'face_nasLab_01_R_SkinPoint',
	255: 'face_noseBase_00_M_SkinPoint',
	256: 'face_sneerDriver_00_L_SkinPoint',
	257: 'face_sneerDriver_00_R_SkinPoint',
	258: 'face_sneerLower_00_L_SkinPoint',
	259: 'face_sneerLower_00_R_SkinPoint',
	260: 'face_sneer_00_L_SkinPoint',
	261: 'face_sneer_00_R_SkinPoint',
	262: 'face_teethBot_00_M_SkinPoint',
	263: 'face_teethTop_00_M_SkinPoint',
	264: 'face_tongue_00_M_SkinPoint',
	265: 'root_main_00_M_SkinPoint',
	266: 'spine_mainBendy_00_M_SkinPoint',
	267: 'clavicle_main_00_L_SkinPoint',
	268: 'arm_shoulderBendy_00_L_SkinPoint',
	269: 'hand_main_00_L_JNT',
	270: 'hand_index_00_L_SkinPoint',
	271: 'hand_main_00_L_SkinPoint',
	272: 'hand_ring_00_L_SkinPoint',
	273: 'hand_pinky_00_L_SkinPoint',
	274: 'hand_thumb_00_L_SkinPoint',
	275: 'clavicle_main_00_R_SkinPoint',
	276: 'arm_shoulderBendy_00_R_SkinPoint',
	277: 'hand_main_00_R_JNT',
	278: 'hand_main_00_R_SkinPoint',
	279: 'hand_middle_00_R_SkinPoint',
	280: 'hand_ring_00_R_SkinPoint',
	281: 'hand_pinky_00_R_SkinPoint',
	282: 'hand_thumb_00_R_SkinPoint',
	283: 'head_main_00_M_SkinPoint',
	284: 'face_jaw_00_M_SkinPoint',
	285: 'EXP_L1_Eye1',
	286: 'EXP_R1_Eye1',
	287: 'EXP_L1_EyeLid1',
	288: 'EXP_R1_EyeLid1',
	289: 'EXP_L1_EyeLid2',
	290: 'EXP_R1_EyeLid2',
	292: 'EXP_L1_WingArm1Twist1',
	293: 'EXP_R1_WingArm1Twist1',
	296: 'waterfall_top_sound',
	297: 'waterfall_bottom_sound'
};

const CRC_BONE_NAMES = {
	3142542542: 'ToeR',
	1094736301: 'ToeL',
	87406847: 'ChestR',
	4282025372: 'ChestL',
	2149808493: 'Neck',
	3947676041: 'LegL',
	289668330: 'LegR',
	1187100303: 'B_Loin_01',
	455993219: 'F_Loin_01',
	133952906: 'WristL',
	1475065404: 'CalfL',
	3775641732: 'KneeR',
	2917436255: 'CalfR',
	453281255: 'KneeL',
	3754485557: 'B_Loin_02',
	2183444025: 'F_Loin_02',
	4112746159: 'F_Loin_03',
	3987563274: '$CAH',
	2904086604: '$CPP',
	524081717: '$CSS',
	1025530540: '$HIT',
	2170048406: '$CST',
	2556568384: '$ESD',
	3217595452: '$FD1',
	3562477949: '$FR0',
	1451682: '$FL0',
	3818595516: '$BWP',
	227886480: '$BWR',
	656719658: '$SHL',
	3710616137: '$SHR',
	2627590982: '$TRD',
	3747058587: '$DTH',
	2586090777: '$FSD',
	3389779667: '$SCD',
	3985447072: 'Ear_L_01',
	2713847615: 'EyebrowR',
	1540176476: 'EyebrowL',
	1565210636: 'Ear_R_01',
	310207871: 'SpineUp',
	1954826522: 'Ear_L_02',
	3292686774: 'Ear_R_02',
	200542651: 'Tail01',
	2466076673: 'Tail02',
	699064172: 'Object26',
	841976507: 'MiddleFingerTipR',
	2353668594: 'IndexFingerTipR',
	2319604107: 'ThumbTipR',
	1884120296: 'ThumbTipL',
	1984240785: 'IndexFingerTipL',
	3357587416: 'MiddleFingerTipL',
	3157792292: 'RingFingerTipR',
	3380046314: 'PinkyFingerTipR',
	863523977: 'PinkyFingerTipL',
	1178020679: 'RingFingerTipL',
	2124421159: 'Plane01',
	3886631325: 'Plane02',
	4278575356: '-EF_Eyelid01',
	2435095781: '-EF_Eyelid_Death',
	2602753973: 'EyeBowL',
	1630397142: 'EyeBowR',
	2301297742: '$BWA',
	2056418566: '$BWS',
	1236608114: 'Belly',
	2043534398: 'Plane05',
	1756834604: 'HipL',
	2461537871: 'HipR',
	4256852168: 'dSpine1_joint',
	1991852656: 'Spine2_joint',
	1280356454: '-Eye01',
	3503180228: 'Spine3_joint',
	1113222609: 'Tail1_joint',
	4274609575: 'LMLeg_joint45',
	3466169200: 'RMLeg_joint48',
	374515731: 'LFLeg_joint46',
	3356237800: 'RFLeg_joint49',
	1941075788: 'Tail2_joint',
	4188314046: 'LMLeg_joint41',
	3074765780: 'RMLeg_joint41',
	2285256112: 'LFLeg_joint41',
	3336017882: 'RFLeg_joint41',
	3586489592: 'Tail3_joint',
	1541885741: 'RLLeg_joint40',
	3313752718: 'RLLeg_joint47',
	1622001668: 'LMLeg_joint42',
	776757870: 'RMLeg_joint42',
	289369098: 'LFLeg_joint42',
	1608435296: 'RFLeg_joint42',
	274874998: 'Tail4_joint',
	752910267: 'RLLeg_joint41',
	1010067695: 'RLLeg_joint042',
	397080722: 'LMLeg_joint43',
	1498108664: 'RMLeg_joint43',
	685373174: 'RFLeg_joint43',
	3051957761: 'RLLeg_joint42',
	1261656185: 'RLLeg_joint043',
	3270385303: 'RLLeg_joint43',
	3579301338: 'RLLeg_joint044',
	2601158378: 'HeadScale_joint22',
	1714969756: 'LFLeg_joint43',
	1320797406: 'FinLeft_joint50',
	2639070569: 'FinRight_joint51',
	3160519086: 'NoseLeft_joint18',
	1694731022: 'Spine1Sale_joint',
	4287748709: 'Spine2Scale_joint',
	1681167882: 'Spine3Scale_joint',
	244018153: 'TailScale_joint',
	3056783546: 'Tail3Scale_joint',
	2568972396: 'Taile4Scale_joint',
	3738240529: 'Hips',
	2118608204: 'LegBackL01',
	1761602358: 'LegBackR01',
	1688372140: 'SpineUpper',
	3880662262: 'LegBackL02',
	4059478668: 'LegBackR02',
	2911396259: 'Hump',
	3774419696: 'LegFrontL01',
	4131495050: 'LegFrontR01',
	3176988174: 'FootBackL',
	1196671853: 'FootBackR',
	2045789002: 'LegFrontL02',
	1867042096: 'LegFrontR02',
	2211631441: 'ToeBackL',
	2044587058: 'ToeBackR',
	2906586403: 'FootFrontL',
	1462878272: 'FootFrontR',
	1456750441: 'ToeFrontL',
	2900034058: 'ToeFrontR',
	2828305040: 'elbow_L',
	1385938931: 'elbow_R',
	1073108840: 'hip_L',
	3321457163: 'hip_R',
	286571785: 'ankle_L',
	3944448106: 'ankle_R',
	248179880: 'Plane04',
	73869075: 'SpineLower',
	3713458406: 'hand_R',
	2424878462: 'thumb_L',
	1787267101: 'thumb_R',
	156616400: 'Lower_01',
	3862048847: 'Upper_01',
	2421987178: 'Lower_02',
	2336852693: 'Leg01Front_L',
	1995865176: 'Leg01_Front_R',
	2134598133: 'Upper_02',
	3881543676: 'Lower_03',
	2652958531: 'Leg01Middle_L',
	597339540: 'Leg01_Middle_R',
	96898358: 'Leg02Front_L',
	1333477533: 'Leg02_Front_R',
	138170723: 'Upper_03',
	2034184799: 'Lower_04',
	659936916: 'Leg01_Back_L',
	3713723383: 'Leg01_Back_R',
	849488884: 'Leg02_Middle_L',
	3366786711: 'Leg02_Middle_R',
	3379334568: 'Leg03Front_L',
	1476416734: 'Leg03_Front_R',
	2522399936: 'Upper_04',
	238551753: 'Lower_05',
	2849689975: 'Leg02_Back_L',
	1406528532: 'Leg02_Back_R',
	3714072778: 'Leg03_Middle_L',
	661618089: 'Leg03_Middle_R',
	3781162070: 'Upper_05',
	2536592243: 'Lower_06',
	1701892585: 'Leg03_Back_L',
	2675960970: 'Leg03_Back_R',
	2018944492: 'Upper_06',
	2734454220: 'JawTopL',
	2836712998: 'JawBottomL',
	1492338863: 'JawTopR',
	1394340677: 'JawBottomR',
	320446612: 'PinkyL01',
	324882040: 'IndexL01',
	94449390: 'PinkyR01',
	98942978: 'IndexR01',
	2316366126: 'PinkyL02',
	2320768962: 'IndexL02',
	2628288340: 'PinkyR02',
	2632749496: 'IndexR02',
	4246192568: 'PinkyL03',
	4250087252: 'IndexL03',
	3954134978: 'PinkyR03',
	3958087982: 'IndexR03',
	117032577: 'foot_L',
	4116633036: 'knee_L',
	4244044770: 'foot_R',
	257026223: 'knee_R',
	1839222075: 'finger_L',
	2544857176: 'finger_R',
	2427353355: 'Plane03',
	2701186468: 'arm_L',
	1527769287: 'arm_R',
	2006816958: 'eye_R',
	2375198173: 'eye_L',
	660200837: 'hand_L',
	2502312157: '-Blid_L01',
	131383389: '-Flid_R01',
	3827894237: 'Blid_L',
	505821886: 'Blid_R',
	2142782923: 'Flid_L',
	2243393704: 'Flid_R',
	1116453182: 'GEO_EyelidL',
	3095692381: 'GEO_EyelidR',
	717968576: 'CheekL',
	3502533027: 'CheekR',
	902861035: 'Geo_EyeLid_Death',
	2905535025: 'fin',
}

/**
 * Get the label for a bone.
 * @param {number} bone_id  - The bone ID.
 * @param {number} index - The bone index.
 * @param {number} crc - CRC for fallback
 * @returns {string} The bone label.
 */
const get_bone_name = (bone_id, index, crc) => {
	if (bone_id in BONE_NAMES)
		return 'bone_' + BONE_NAMES[bone_id];
	
	if (crc in CRC_BONE_NAMES)
		return 'bone_' + CRC_BONE_NAMES[crc];

	return 'bone_' + index;
}

module.exports = { get_bone_name };